<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
        	<form class="form-horizontal m" id="form-weeklyReport-edit" th:object="${weeklyReport}">
           		 <input id="weekId" name="weekId" th:field="*{weekId}"  type="hidden">
				<input name="userId"  type="hidden" id="chooseId" th:field="*{userId}"/>
				<div class="form-group">
					<label class="col-sm-3 control-label">工作内容：</label>
					<div class="col-sm-8">
						<textarea id="workContent" name="workContent" class="form-control" style="height: 100px;">[[*{workContent}]]</textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">工作开始时间：</label>
					<div class="col-sm-4">
						<input id="commonDateTimeStart" name="workStart" th:field="*{workStart}" class="form-control" type="text" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">工作结束时间：</label>
					<div class="col-sm-4">
						<input id="commonDateTimeEnd" name="workEnd" th:field="*{workEnd}" class="form-control" type="text" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">审批人：</label>
					<div class="col-sm-3">
						<input class="form-control" type="text" name="userName" onclick="chooseUser()" readonly="true" id="chooseName" th:field="*{user.userName}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">备注：</label>
					<div class="col-sm-8">
						<textarea id="remark" name="remark" class="form-control" style="height: 100px;">[[*{remark}]]</textarea>
					</div>
				</div>
				<div class="form-group">
					<div class="form-control-static col-sm-offset-9">
						<button type="submit" class="btn btn-primary">提交</button>
						<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
					</div>
				</div>
			</form>
		</div>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "module/weeklyReport"
		$("#form-weeklyReport-edit").validate({
			rules:{
                workContent:{
					required:true,
                    minlength: 5,
                    maxlength: 500
				},
                workStart:{
                    required:true,
                },
                workEnd:{
                    required:true,
                    checkEndTime:true
                }
			},
            messages:{
                workEnd:{
                    checkEndTime:"结束时间大于开始时间"
                }
            },
			submitHandler: function(form) {
				// $.operate.save(prefix + "/edit", $('#form-weeklyReport-edit').serialize());
                edit();
			}
		});

        function edit() {
            var weekId = $("input[name='weekId']").val();
            var workContent = $("#workContent").val();
            var workStart = $("input[name='workStart']").val();
            var workEnd = $("input[name='workEnd']").val();
            var userId = $("input[name='userId']").val();
            var remark = $("#remark").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/edit",
                data : {
                    "weekId" :weekId,
                    "workContent": workContent,
                    "workStart": workStart,
                    "workEnd": workEnd,
                    "userId":userId,
                    "remark":remark
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }

        function chooseUser() {
            var url = ctx + "system/user/chooseUser/";
            $.modal.open("选择审批人", url, '600', '380');
        }

	</script>
</body>
</html>
